package com.csk.zsk.compents.interceptor;

import java.util.Map;

import javax.servlet.http.HttpSession;

import com.csk.zsk.commons.utils.web.struts2.Struts2Utils;
import com.csk.zsk.compents.entity.User;
import com.csk.zsk.compents.utils.Constants;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class FilterInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 2937946684705322793L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		boolean flag = false;
		Map parameters = invocation.getInvocationContext().getParameters();   
		if(parameters.get("isAndroid")!=null){
			return invocation.invoke();
		}
		
		HttpSession session = Struts2Utils.getSession();
		if (session != null && session.getAttribute(Constants.USER_SESSION) != null) {
			User user = (User) session.getAttribute(Constants.USER_SESSION);
			if (user != null) {
				return invocation.invoke();
			} else {
				if (flag == false) {
					return Action.LOGIN;
				}
				return invocation.invoke();
			}
		} else {
			if (flag == false) {
				return Action.LOGIN;
			}
			return invocation.invoke();
		}
	}

}